package com.dididoctor.patient.Activity.Doctor.Doctordetail;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.View;
import android.widget.TextView;

import com.dididoctor.patient.MV.adapter.CommonAdapter;
import com.dididoctor.patient.MV.adapter.ViewHolder;
import com.dididoctor.patient.R;
import com.dididoctor.patient.Utils.LoaderImage;
import com.dididoctor.patient.Utils.UserHeadImage;
import com.dididoctor.patient.Utils.Util;
import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.listener.ImageLoadingListener;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2016/4/11.
 */
public class DoctorDetailAdapter extends CommonAdapter<DoctorEvaluate> {

    private UserHeadImage headImage;
    private LoaderImage loaderImage;
    private TextView mTvName, mTvLevel, mTvRemark, mTvTime;

    public DoctorDetailAdapter(Context context, List datas) {
        super(context, datas, R.layout.item_doctor_detail);
        loaderImage = new LoaderImage(context);
    }

    @Override
    public void convert(int position, ViewHolder helper, DoctorEvaluate item) {
        headImage = helper.getView(R.id.img_user);
        loaderImage.load(headImage, item.getHeadPic(), new ImageLoadingListener() {
            @Override
            public void onLoadingStarted(String s, View view) {
                headImage.setImageResource(R.drawable.img_doctordefault);
            }

            @Override
            public void onLoadingFailed(String s, View view, FailReason failReason) {
                headImage.setImageResource(R.drawable.img_doctordefault);
            }

            @Override
            public void onLoadingComplete(String s, View view, Bitmap bitmap) {

            }

            @Override
            public void onLoadingCancelled(String s, View view) {

            }
        });
        mTvName = helper.getView(R.id.tv_item_name);
        mTvLevel = helper.getView(R.id.tv_item_level);
        mTvRemark = helper.getView(R.id.tv_item_remark);
        mTvTime = helper.getView(R.id.tv_item_time);

        mTvName.setText(item.getName());
        mTvRemark.setText(item.getRemark());
        mTvTime.setText(getDayStr(item.getStartTime()));
        if (Util.toInteger(item.getLevel()) == 5) {
            mTvLevel.setText("满意");
        } else if (Util.toInteger(item.getLevel()) == 4) {
            mTvLevel.setText("一般");
        } else {
            mTvLevel.setText("不满意");
        }

    }

    public static String getDayStr(String time) {
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = null;
        try {
            date = simpleDateFormat.parse(time);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        return simpleDateFormat.format(date);
    }
}
